Skip to content

refactor: tanstack-query for api state, zustand for accounts and settings state#2637

Draft
setchy wants to merge 4 commits into
mainfrom
refactor/zustand-auth-settings
Draft

refactor: tanstack-query for api state, zustand for accounts and settings state#2637
setchy wants to merge 4 commits into
mainfrom
refactor/zustand-auth-settings

Conversation

@setchy

@setchy setchy commented Feb 21, 2026

Copy link
Copy Markdown
Member

Summary

Completes the renderer state-management migration started with the filters store (#2633): TanStack Query owns all API state, Zustand stores own all client state, and AppContext is gone.

  • TanStack Query owns notification fetching, polling (refetchInterval), caching, retries, and mutations (mark as read/done, unsubscribe), replacing the manual useState/timer-based fetching in useNotifications.
  • Zustand stores own accounts (useAccountsStore) and settings (useSettingsStore) state, joining the existing filters store. Both persist to their own local storage keys, with a one-time migration from the legacy gitify-storage key.
  • AppContext is fully retired. Components consume focused hooks directly: useNotifications() (shared query cache), useLogins() (forge login/logout flows), useOnlineStatus(), and a small transient store for global-shortcut registration state. A one-mount GlobalEffects component hosts app-level side effects (theme, tray, shortcut registration, app reset, account refresh, notification alerts).

Details

  • Instant client-side filtering: the notifications cache holds unfiltered data and all filtering happens in the query select, so narrowing and loosening filters applies instantly with zero API calls. Enrichment is limited to filter-passing notifications to bound API usage.
  • Notification queries are keyed by account identity (UUIDs), not account count, so adding/removing/swapping accounts always resolves to distinct cache entries; re-authentication explicitly invalidates.
  • Store side effects (auto launch, tray icons, keep-window-on-blur, zoom sync) live in stores/subscriptions.ts, initialized once on app startup.
  • The accounts store delegates to the existing utils/auth/utils logic (multi-forge upsert, scope checks), sanitizes persisted state on rehydrate, and owns token re-encryption migration (run once before the first account refresh).
  • Fetch scheduling honours the interval/inactivity fetchType setting: interval mode maps to TanStack Query's refetchInterval; inactivity mode reuses useInactivityTimer.
  • Online/offline state flows from TanStack Query's onlineManager through the renderer to the tray (ITrayColorUpdate IPC payload) instead of polling net.isOnline() in the main process, and surfaces an OFFLINE error state in the UI.
  • @octokit/plugin-retry removed; retries are handled at the query layer (queries and mutations). useIntervalTimer removed (superseded by query polling).
  • Tests: component tests keep the renderWithProviders options API, now backed by globally mocked hooks (__helpers__/hook-mocks.ts) plus direct store seeding; hook tests exercise the real implementations via vi.unmock.

@github-actions github-actions Bot added dependency Dependency updates refactor Refactoring of existing feature labels Feb 21, 2026
@afonsojramos afonsojramos force-pushed the refactor/zustand-auth-settings branch from 76ae87a to 61581b7 Compare July 16, 2026 01:19
@afonsojramos afonsojramos changed the title refactor: tanstack-query for api state, zustand for accounts and setting state refactor: tanstack-query for api state, zustand for accounts and settings state Jul 16, 2026
@afonsojramos afonsojramos force-pushed the refactor/zustand-auth-settings branch from 61581b7 to 6881e49 Compare July 16, 2026 01:37
@afonsojramos afonsojramos force-pushed the refactor/zustand-auth-settings branch from 6881e49 to b270e74 Compare July 16, 2026 01:38
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependency Dependency updates refactor Refactoring of existing feature

Development

Successfully merging this pull request may close these issues.

2 participants